﻿<UserControl x:Class="ClientOverflow.UserControls.QuestionView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <StackPanel>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <StackPanel  Grid.Column="0">
                <TextBlock Text="{Binding Title}" Padding="5" />
                <TextBlock Text="{Binding Content}" Padding="5" />
            </StackPanel>
            <StackPanel Grid.Column="1" >
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="Votes "/>
                    <TextBlock Text="{Binding Votes}"/>
                </StackPanel>
                <Button Grid.Row="0" Grid.Column="1" Padding="5" Command="{Binding VoteUpCommand}">Up</Button>
                <Button Grid.Row="1" Grid.Column="1" Padding="5" Command="{Binding VoteDownCommand}">Down</Button>
            </StackPanel>
        </Grid>

        <ListBox ItemsSource="{Binding Answers}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
                        <StackPanel.Style>
                            <Style>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding IsCorrect}" Value="True">
                                        <Setter Property="Control.Background" Value="Green"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </StackPanel.Style>
                        <TextBlock Text="{Binding Content}" Padding="5" HorizontalAlignment="Stretch" MinWidth="300" />
                        <StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="Votes "/>
                                <TextBlock Text="{Binding Votes}"/>
                            </StackPanel>
                            <Button Padding="5" Command="{Binding VoteUpCommand}">Up</Button>
                            <Button Padding="5" Command="{Binding VoteDownCommand}">Down</Button>
                            <Button Padding="5" Command="{Binding ChooseAnswerCommand}">Correct!</Button>
                        </StackPanel>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <Border BorderThickness="2">
            <StackPanel>
                <TextBlock Text="New Answer"/>
                <TextBox Text="{Binding NewAnswer.Content, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MinWidth="200" MinHeight="150" AcceptsReturn="True" />
                <Button Command="{Binding PostNewAnswerCommand}" Content="Post answer" HorizontalAlignment="Right" Padding="5"/>
            </StackPanel>
        </Border>
    </StackPanel>
</UserControl>
